var xmlHttpObj = null;

function getXmlHttpRequest() {
	xmlHttpObj = null;

	if (window.XMLHttpRequest) { // Mozilla 浏览器
		xmlHttpObj = new XMLHttpRequest();
		if (xmlHttpObj.overrideMimeType) {
			// 设置MiME类别
			xmlHttpObj.overrideMimeType("text/xml");
		}

	} else if (window.ActiveXObject) {
		try {
			xmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert('该浏览器不适用！请更换浏览器');
			}
		}
	}
	return xmlHttpObj;
}
// 定义可复用的http请求发送函数
function send_request(xmlHttpObj, method, url, params, responseType, callback) {
	// 初始化、指定处理函数、发送请求的函数
	// 开始初始化XMLHttpRequest对象

	if (!xmlHttpObj) { // 异常，创建对象实例失败
		window.alert("不能创建XMLHttpRequest对象实例.");
		return false;
	}
	if (responseType.toLowerCase() == "text") {
		xmlHttpObj.onreadystatechange = callback;
	} else if (responseType.toLowerCase() == "xml") {
		xmlHttpObj.onreadystatechange = callback;
		window.alert("响应类别参数错误。");
		return false;
	}

	// 确定发送请求的方式和URL以及是否异步执行下段代码
	if (method.toLowerCase() == "get") {
		xmlHttpObj.open(method, url);
		// xmlHttpObj.setRequestHeader('dataType', 'JSONP');
		xmlHttpObj.send();
	}

	else if (method.toLowerCase() == "post") {
		xmlHttpObj.open(method, url, false);
		xmlHttpObj.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
		xmlHttpObj.setRequestHeader("Accept-Language", "zh-cn");
		xmlHttpObj.send(params);
	} else {
		window.alert("http请求类别参数错误。");
		return false;
	}
	// xmlHttpObj.send();
}

function getRequestJSON(request){
	return JSON.parse(request.responseText);
}